package com.mydemo.io.socket;

import java.io.*;
import java.net.Socket;

/**
 * <p></p >
 *
 * @author liming1
 * @version $Id: SocketThread, v1.0 2019-09-26 15:21 liming1 Exp $
 */
public class SocketThread implements Runnable {

    private Socket socket;

    public SocketThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            System.out.println("开始处理");
            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();// 获取一个输出流，向服务端发送信息
            PrintStream out = System.out;
            PrintWriter printWriter = new PrintWriter(outputStream);// 将输出流包装成打印流
            byte[] buffer = new byte[2048];
            int count;
            while ((count = inputStream.read(buffer)) != -1) {
                out.write(buffer, 0, count);
            }
            printWriter.flush();
            inputStream.close();
            printWriter.close();
        } catch (Exception e) {
            System.out.println("处理异常" + e.getMessage());
        }
    }
}
